package everydayDatas

import (
	"gorm.io/gorm"
	"time"
)

type EverydayDatas struct {
	Id            int32     `json:"id" gorm:"column:id"`
	InfluencersId int32     `json:"influencers_id" gorm:"column:influencers_id"`
	Time          time.Time `json:"time" gorm:"column:time"`
	LiveMoney     float64   `json:"live_money" gorm:"column:live_money"`
	AdMoney       float64   `json:"ad_money" gorm:"column:ad_money"`
	ShopMoney     float64   `json:"shop_money" gorm:"column:shop_money"`
	TotalMoney    float64   `json:"total_money" gorm:"column:total_money"`
	FansRaise     int32     `json:"fans_raise" gorm:"column:fans_raise"`
	PlayNewRaise  int32     `json:"play_new_raise" gorm:"column:play_new_raise"`
	NewLikeNum    int32     `json:"new_like_num" gorm:"column:new_like_num"`
	CommentNum    int32     `json:"comment_num" gorm:"column:comment_num"`
	NewShareNum   int32     `json:"new_share_num" gorm:"column:new_share_num"`
	PhotoCnt      int32     `json:"photo_cnt" gorm:"column:photo_cnt"`
	LiveTime      int32     `json:"live_time" gorm:"column:live_time"`
	LiveTimeVaild int32     `json:"live_time_vaild" gorm:"column:live_time_vaild"`
	AdOrder       int32     `json:"ad_order" gorm:"column:ad_order"`
	ShopSales     float64   `json:"shop_sales" gorm:"column:shop_sales"`
	ShopOrder     int32     `json:"shop_order" gorm:"column:shop_order"`
	ShopGold      float64   `json:"shop_gold" gorm:"column:shop_gold"`
	CreatedAt     time.Time `json:"created_at" gorm:"column:created_at"`
	UpdatedAt     time.Time `json:"updated_at" gorm:"column:updated_at"`
	DeletedAt     time.Time `json:"deleted_at" gorm:"column:deleted_at"`
}

func (*EverydayDatas) TableName() string {
	return "hx_everyday_datas"
}

func NewEverydayDatas() *EverydayDatas {
	return &EverydayDatas{}
}

//我的任务数据统计
func (e *EverydayDatas) SummaryData(db *gorm.DB, start, end string, inf_id int32) (map[string]interface{}, error) {
	m := make(map[string]interface{}, 4)
	//var yesterday float64
	var this_month float64
	//var duration int32
	var thi_month_duration int32
	query := db.Model(&EverydayDatas{}).Where("time >= ? and time <= ?", start, end).Where("influencers_id", inf_id).Debug().Select("live_time", "total_money")
	err := query.First(&e).Error //昨日流水
	if err != nil {
		m["yesterday"] = 0
		m["duration"] = 0
	} else {
		m["yesterday"] = e.TotalMoney
		m["yesterday"] = e.LiveTime
	}
	monthError := query.Pluck("sum(total_money)", &this_month).Error //当月总流水
	if monthError != nil {
		m["this_month"] = 0
	} else {
		m["this_month"] = this_month
	}
	_ = query.Select("live_time").Pluck("sum(live_time)", &thi_month_duration).Error //当月开播市场
	m["thi_month_duration"] = thi_month_duration
	return m, nil
}
